import * as ImGui from "../../imgui/imgui";
import * as ImGui_Impl from "../../imgui/imgui_impl";
// import { ShowDemoWindow } from "./imgui_demo";
import { MyTestWindow } from "./mywindow";
import { ImguiMgr } from "../../imgui/imgui-mgr";
import { ShowUserGuide_cn, ShowDemoWindow_cn } from "./imgui_demo_cn";
export class ImguiTest {
    private _imguiMgr: ImguiMgr;
    constructor() {

    }
    init() {
        this._imguiMgr = new ImguiMgr();
        this._imguiMgr.registWindow(new MyTestWindow());
        //demo
        this._imguiMgr.registWindow({
            isShow: true,
            key: "demo_cn",
            loop: ShowDemoWindow_cn as any,
        })
        this._imguiMgr.setFPS(30);
        this._imguiMgr.startUp();
    }


}
// let f: number = 0.0;
// /* static */ let counter: number = 0;
// let done: boolean = false;
// let show_demo_window: boolean = true;
// let show_another_window: boolean = false;
// const clear_color: ImGui.ImVec4 = new ImGui.ImVec4(0.45, 0.55, 0.60, 1.00);
// let show_my_window: boolean = false;
// function _loop(time: number): void {
//     // Poll and handle events (inputs, window resize, etc.)
//     // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
//     // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
//     // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
//     // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.

//     // Start the Dear ImGui frame
//     ImGui_Impl.NewFrame(time);
//     ImGui.NewFrame();

//     // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
//     if (!done && show_demo_window) {
//         done = /*ImGui.*/ShowDemoWindow((value = show_demo_window) => show_demo_window = value);
//     }

//     // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
//     {
//         // static float f = 0.0f;
//         // static int counter = 0;

//         ImGui.Begin("Hello, world!");                          // Create a window called "Hello, world!" and append into it.

//         ImGui.Text("This is some useful text.");               // Display some text (you can use a format strings too)
//         ImGui.Checkbox("Demo Window", (value = show_demo_window) => show_demo_window = value);      // Edit bools storing our windows open/close state
//         ImGui.Checkbox("Another Window", (value = show_another_window) => show_another_window = value);
//         // ImGui.Checkbox("MyWindow", (value = myWindow.isShow) => myWindow.isShow = value);

//         ImGui.SliderFloat("float", (value = f) => f = value, 0.0, 1.0);            // Edit 1 float using a slider from 0.0f to 1.0f
//         // ImGui.ColorEdit4("clear color", clear_color); // Edit 3 floats representing a color

//         if (ImGui.Button("Button"))                            // Buttons return true when clicked (NB: most widgets return true when edited/activated)
//             counter++;
//         ImGui.SameLine();
//         ImGui.Text(`counter = ${counter}`);

//         ImGui.Text(`Application average ${(1000.0 / ImGui.GetIO().Framerate).toFixed(3)} ms/frame (${ImGui.GetIO().Framerate.toFixed(1)} FPS)`);

//         // ImGui.Checkbox("Memory Editor", (value = memory_editor.Open) => memory_editor.Open = value);
//         // if (memory_editor.Open)
//         //     memory_editor.DrawWindow("Memory Editor", ImGui.bind.HEAP8.buffer);
//         const mi: Bind.mallinfo = ImGui.bind.mallinfo();
//         // ImGui.Text(`Total non-mmapped bytes (arena):       ${mi.arena}`);
//         // ImGui.Text(`# of free chunks (ordblks):            ${mi.ordblks}`);
//         // ImGui.Text(`# of free fastbin blocks (smblks):     ${mi.smblks}`);
//         // ImGui.Text(`# of mapped regions (hblks):           ${mi.hblks}`);
//         // ImGui.Text(`Bytes in mapped regions (hblkhd):      ${mi.hblkhd}`);
//         ImGui.Text(`Max. total allocated space (usmblks):  ${mi.usmblks}`);
//         // ImGui.Text(`Free bytes held in fastbins (fsmblks): ${mi.fsmblks}`);
//         ImGui.Text(`Total allocated space (uordblks):      ${mi.uordblks}`);
//         ImGui.Text(`Total free space (fordblks):           ${mi.fordblks}`);
//         // ImGui.Text(`Topmost releasable block (keepcost):   ${mi.keepcost}`);
//         // if (ImGui.ImageButton(image_gl_texture, new ImVec2(48, 48))) {
//         //     // show_demo_window = !show_demo_window;
//         //     image_url = image_urls[(image_urls.indexOf(image_url) + 1) % image_urls.length];
//         //     if (image_element) {
//         //         image_element.src = image_url;
//         //     }
//         // }
//         // if (ImGui.IsItemHovered()) {
//         //     ImGui.BeginTooltip();
//         //     ImGui.Text(image_url);
//         //     ImGui.EndTooltip();
//         // }
//         // if (ImGui.Button("Sandbox Window")) { show_sandbox_window = true; }
//         // if (show_sandbox_window)
//         //     ShowSandboxWindow("Sandbox Window", (value = show_sandbox_window) => show_sandbox_window = value);
//         // ImGui.SameLine();
//         // if (ImGui.Button("Gamepad Window")) { show_gamepad_window = true; }
//         // if (show_gamepad_window)
//         //     ShowGamepadWindow("Gamepad Window", (value = show_gamepad_window) => show_gamepad_window = value);
//         // ImGui.SameLine();
//         // if (ImGui.Button("Movie Window")) { show_movie_window = true; }
//         // if (show_movie_window)
//         //     ShowMovieWindow("Movie Window", (value = show_movie_window) => show_movie_window = value);

//         // if (font) {
//         //     ImGui.PushFont(font);
//         //     ImGui.Text(`${font.GetDebugName()}`);
//         //     if (font.FindGlyphNoFallback(0x5929)) {
//         //         ImGui.Text(`U+5929: \u5929`);
//         //     }
//         //     ImGui.PopFont();
//         // }

//         ImGui.End();
//     }

//     // 3. Show another simple window.
//     if (show_another_window) {
//         ImGui.Begin("Another Window", (value = show_another_window) => show_another_window = value, ImGui.WindowFlags.AlwaysAutoResize);
//         ImGui.Text("Hello from another window!");
//         if (ImGui.Button("Close Me"))
//             show_another_window = false;
//         ImGui.End();
//     }
//     // 4. show my window
//     myWindow.windowLoop();

//     ImGui.EndFrame();

//     // Rendering
//     ImGui.Render();
//     // const gl: WebGLRenderingContext | null = ImGui_Impl.gl;
//     // if (gl) {
//     //     gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
//     //     gl.clearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
//     //     gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
//     //     gl.enable(gl.BLEND);
//     //     gl.clear(gl.COLOR_BUFFER_BIT);
//     //     //gl.useProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound
//     // }

//     // const ctx: CanvasRenderingContext2D | null = ImGui_Impl.ctx;
//     // if (ctx) {
//     //     // ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
//     //     ctx.fillStyle = `rgba(${clear_color.x * 0xff}, ${clear_color.y * 0xff}, ${clear_color.z * 0xff}, ${clear_color.w})`;
//     //     ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
//     // }


//     ImGui_Impl.RenderDrawData(ImGui.GetDrawData());

//     if (typeof (window) !== "undefined") {
//         window.requestAnimationFrame(done ? _done : _loop);
//     }
// }
// async function _done(): Promise<void> {
//     const gl: WebGLRenderingContext | null = ImGui_Impl.gl;
//     if (gl) {
//         gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
//         gl.clearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
//         gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
//         gl.enable(gl.BLEND);
//         gl.clear(gl.COLOR_BUFFER_BIT);
//     }

//     const ctx: CanvasRenderingContext2D | null = ImGui_Impl.ctx;
//     if (ctx) {
//         ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
//     }

//     // Cleanup
//     ImGui_Impl.Shutdown();
//     ImGui.DestroyContext();

//     console.log("Total allocated space (uordblks) @ _done:", ImGui.bind.mallinfo().uordblks);
// }
// // async function LoadArrayBuffer(url: string): Promise<ArrayBuffer> {
// //     const response: Response = await fetch(url);
// //     return response.arrayBuffer();
// // }
// // async function AddFontFromFileTTF(url: string, size_pixels: number
// //     , font_cfg: ImFontConfig | null = null, glyph_ranges: number | null = null): Promise<ImFont> {
// //     font_cfg = font_cfg || new ImFontConfig();
// //     font_cfg.Name = font_cfg.Name || `${url.split(/[\\\/]/).pop()}, ${size_pixels.toFixed(0)}px`;
// //     return GetIO().Fonts.AddFontFromMemoryTTF(await LoadArrayBuffer(url), size_pixels, font_cfg, glyph_ranges);
// // }